#coding=utf-8

from oss.oss_api import *


key_id = 'ACSgvdYy54n9Zns8'
key_secret = '3frFAS8g9V'

# key_id = 'woqb8ylqgsp639vw3bfkkrm7'
# key_secret = 'uzzA0U5JbyujtflgItNyF47wQtA='

#以杭州为例
endpoint='oss-cn-hangzhou.aliyuncs.com'
accessKeyId, accessKeySecret=key_id, key_secret
oss = OssAPI(endpoint, accessKeyId, accessKeySecret)
print(dir(oss))

#设置bucket权限为私有
bucket = 'myhfjiacn'
# res = oss.create_bucket(bucket, "private") #设置bucket权限为私有
# print "%s\n%s" % (res.status, res.read())

# 删除Bucket
# res = oss. delete_bucket(bucket)
# print "%s\n%s" % (res.status, res.read())

#直接上传字符串
object = 'f1/aa.txt'
res=oss.put_object_from_string(bucket, object, "string content")
print "%s\n%s" % (res.status, res.read())

#下载object到“file_path”
file_path = 'http://img1.gtimg.com/ninja/0/ninja143156339622167.jpg'
res=oss.get_object(bucket, "object_test.jpg", file_path)
print "%s\n%s\n%s" % (res.status, res.read(),res.getheaders())



# res = oss.list_all_my_buckets()
# print(res.read())
# buckets_xml=oss_xml_handler.GetServiceXml(res.read())
# for bucket_info in buckets_xml.bucket_list:
#     print "----------------------------------------"
#     print "Location:"+bucket_info.location
#     print "Name:"+bucket_info.name
#     print "CreationDate:"+bucket_info.creation_date


